<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Title           Album model
 *
 * @package        appworkz
 * Location        application/frontend/models/photo
 *
 * @author         Ruwan - ruwanpathmalal@gmail.com
 * @copyright      appworkz
 *
 * created on      28-12-2012, 10:30AM by Ruwan
 * updated on      dd-mm-yyy, hh:mm by {name}
 *
 * Description     Functionalities related to album
 *
 * */

//  CI 2.0 Compatibility
if(!class_exists('CI_Model')) { class CI_Model extends Model {} }


class Album_model extends CI_Model
{

    /**
     * Holds an array of tables used
     *
     * @var string
     **/
    public $mastables = array();


    /**
     * __construct
     *
     * @param none
     * @access public
     * @return void
     * @author Hayesha - hayesha.somarathne@cyberlmj.com
     **/
    public function __construct() {
        parent::__construct();
        $this->mastables['business_album'] = 'business_album';
     }




    /**
     * This will cerates a new photo album
     *
     * @param array $data
     * @return int last inserted id
     * @author Ruwan - ruwanpathmalal@gmail.com
     **/
    public function add($data = array())
    {
        $this->db->insert($this->mastables['business_album'], $data);
		return $this->db->insert_id();
    }

    /**
     * This checks whether the user has already created an album with the provided name and album type
     *
     * @param string $business_id
     * @param int $album_name
     * @param int $album_type
     * @access public
     * @return boolean
     * @author Ruwan - ruwanpathmalal@gmail.com
     **/
    public function is_available($business_id,$album_name,$album_type){
		$this->db->select('*');
		$this->db->from($this->mastables['business_album']);
		$this->db->where(array('BusinessID'=>$business_id,'AlbumName'=>$album_name,'AlbumTypeID'=>$album_type,'IsDelete'=>0));
		if($this->db->count_all_results()){
			return TRUE;
		} else {
			return FALSE;
		}
    }

    /**
     * Update the album details
     *
     * @param int $album_id
     * @param array $data
     * @access public
     * @return boolean
     * @author Ruwan - ruwanpathmalal@gmail.com
     **/
    public function update($album_id,$data) {
        $this->db->where(array('AlbumID'=>$album_id));
        return $this->db->update($this->mastables['business_album'], $data);
    }

     /**
     * Remove an album entirely
     *
     * @param int $business_id
     * @param string $album_name
     * @param int $type
     * @access public
     * @return boolean
     * @author Ruwan - ruwanpathmalal@gmail.com
     **/    
    public function get_album_id_by_filters($business_id,$album_name,$type){
    	$this->db->select('*');
    	$this->db->from($this->mastables['business_album']);
    	$this->db->where(array('BusinessID'=>$business_id,'AlbumName'=>$album_name,'AlbumTypeID'=>$type,'IsDelete'=>0));
    	$query = $this->db->get(); 
    	return $result = $query->row_array();
    	 
    }
    
    /**
     * Remove an album entirely
     *
     * @param array $filters
     * @param int $offset
     * @param int $limit
     * @access public
     * @return array
     * @author Ruwan - ruwanpathmalal@gmail.com
     **/
    public function get_albums($filters=array(),$limit=NULL,$offset=NULL) {
    	$this->db->select('AlbumID,AlbumName,BusinessID,AlbumTypeID');
    	$this->db->from($this->mastables['business_album']);
    	$this->db->where('IsDelete',0);
    	if(!empty($filters)) {
    		$this->db->where($filters);
    	}
    	if($limit != NULL){
    		if($offset != NULL){
    			$this->db->limit($limit,$offset);
    		} else {
    			$this->db->limit($limit);
    		}
    	}
    	$query = $this->db->get();
    	return $query->result_array();
    }

}

/* End of file album_model.php */
/* Location: ./application/frontend/models/activity/photo/album_model.php */